const { Sequelize } = require('sequelize');
const config = {
  host: "localhost",
  database: "donation",
  username: "root",
  password: "",
  port: 3306
}
const sequelize = new Sequelize( //实例
  config.database,
  config.username,
  config.password,
  {
    host: config.host,
    dialect: "mysql",
    pool: {
      max: 5,//最大连接池连接数量
      min: 0,
      idle: 10000,//如果一个线程10秒内没被使用则释放
    },
    logging: true,//
  }
)
const UserModel = require('./model/user')(sequelize)
const adviceModel = require('./model/advice')(sequelize)
const commentModel = require('./model/comment')(sequelize)
const recordModel = require('./model/record')(sequelize)
const articleModel = require('./model/article')(sequelize)
const typeModel = require('./model/type')(sequelize)
const orderModel = require('./model/order')(sequelize)

UserModel.hasMany(commentModel, {foreignKey: 'userId'})
commentModel.belongsTo(UserModel, {foreignKey: 'userId'})


module.exports = {
  sequelize,
  UserModel,
  adviceModel,
  commentModel,
  recordModel,
  articleModel,
  typeModel,
  orderModel
}
